package com.word.app.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.word.app.pojo.UserInfo;
import com.word.app.service.UserInfoService;
import com.word.app.config.token.JWTUtil;
import com.word.app.mapper.UserInfoMapper;

import org.springframework.stereotype.Service;

/**
* @author 311
* @description 针对表【userInfo】的数据库操作Service实现
* @createDate 2022-06-16 12:13:09
*/
@Service
public class UserInfoServiceImpl extends ServiceImpl<UserInfoMapper, UserInfo>
    implements UserInfoService{

    @Override
    public String login(String username, String password) {
        QueryWrapper<UserInfo> wrapper = new QueryWrapper<>();
        wrapper.eq("name", username);
        UserInfo user =  this.baseMapper.selectOne(wrapper);
        if(user != null && JWTUtil.MD5(user.getPassword()).equals(password))
            return JWTUtil.sign(username);
        return null;
    }

}




